<?php
    $comum = $_GET['comum'];
?>
<html lang="pt-br">
<head>
<link rel="shortcut icon" type="visao/css/image/x-icon" href="imagens/favicon1.ico" />
<link rel="stylesheet" href="/visao/css/estilo.css" type="text/css" media="all" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="visao/js/jquery-1.2.6.pack.js" type="text/javascript"></script>
<script src="visao/js/jquery.maskedinput-1.1.4.pack.js" type="text/javascript" ></script>
        <script type="text/javascript">
            $(document).ready(function(){
            $("#laboratorio").focus();
            $("#telefone").mask("(99)9999-9999");
            $('.relatorio tbody tr').hover(				
            function(){$(this).css("background","#C0C0C0");},
            function(){$(this).css("background","");}
        );
            });</script>
<style type="text/css">
<!--
.style1 {color: #333333}
-->
</style>
</head>
<body>
    <?php
    if ($comum == 'cadLaboratorio'){
            $idEmpresa = $_SESSION['idEmpresa'];
            $numLaboratorios = mysql_num_rows(getLaboratorio($idEmpresa));
            $laboratorio = getLaboratorio($idEmpresa);
      ?>
        <form action="/" method="GET">
          <input type="hidden" name="comum" value="cadNewLaboratorio"/>
          <input  type="submit" value="Novo"/>
      </form>
      <p>&nbsp;</p>
      <fieldset><legend>Laboratórios cadastrados</legend>
      <table class="relatorio" width="940">
          <thead>
              <tr>
                  <th>Laboratório</th>
                  <th>Representante</th>
                  <th>Telefone</th>
                  <th>Alterar</th>
              </tr>
          </thead>
          <tbody>
          <?php
          for ($i=0;$i<$numLaboratorios;$i++){
              mysql_data_seek($laboratorio, $i);
              $arrayLaboratorio = mysql_fetch_array($laboratorio);
                echo '<tr>';
            echo '<td>'.$arrayLaboratorio["nome"].'</td>';
            echo '<td>'.$arrayLaboratorio["representante"].'</td>';
            echo '<td>'.$arrayLaboratorio["telefone"].'</td>';
            echo '<td><a href="/?comum=alterarLaboratorio&id='.$arrayLaboratorio['id'].'">Alterar</a></td>';
                echo '</tr>';
          }
          ?>
          </tbody>
      </table>
      </fieldset>
      <?php
        }
        if ($comum == 'cadNewLaboratorio'){
    ?>
      <h1>Cadastro de Laboratório</h1>
      <p>&nbsp;</p>
     <form action="/" method="post">
                  <input type="hidden" name="operacao" value="cadLaboratorio"/>
      <table width="300" border="0" cellspacing="10" cellpadding="0">
        <tr>
        <td width="64"><div align="right"><span class="style1">Nome:</span></div></td>
          <td width="227"><label>
          <input type="text" name="nome" size="40" required="required" id="laboratorio"/>
          </label></td>
        </tr>
        <tr>
          <td><div align="right"><span class="style1">Representante:</span></div></td>
          <td><input type="text" name="representante" size="40" maxlength="99" /></td>
        </tr>
        <tr>
          <td><div align="right"><span class="style1">Telefone:</span></div></td>
          <td><input name="telefone" type="text" id="telefone" size="12"/></td>
        </tr>
          <td>&nbsp;</td>
          <td><input type="submit" name="cadastraCliente" id="cadastraCliente" value="Cadastrar" />  </td>
        </tr>
      </table>
         </form>
      <?php
        }
        if ($comum == 'alterarLaboratorio'){
            include_once 'modelo/modeloLaboratorio.php';
            $id = addslashes($_GET['id']);
            settype($id, 'integer');
            $laboratorio = mysql_fetch_array(getDadosLaboratorio($id));
    ?>
      <h1>Alterar Laboratório</h1>
      <p>&nbsp;</p>
     <form action="/" method="POST">
      <table width="300" border="0" cellspacing="10" cellpadding="0">
        <tr>
        <td width="64"><div align="right"><span class="style1">Nome:</span></div></td>
          <td width="227"><label>
                  <input type="hidden" name="operacao" value="alterarLaboratorio"/>
                  <input type="hidden" name="id" value="<?php echo $id;?>"/>
                  <input type="text" name="nome" size="40" required="required" value="<?php echo $laboratorio['nome'];?>"/>
          </label></td>
        </tr>
        <tr>
          <td><div align="right"><span class="style1">Representante:</span></div></td>
          <td><input type="text" name="representante" size="40" maxlength="99"  value="<?php echo $laboratorio['representante'];?>"/></td>
        </tr>
        <tr>
          <td><div align="right"><span class="style1">Telefone:</span></div></td>
          <td><input name="telefone" type="text" id="telefone" size="12" value="<?php echo $laboratorio['telefone'];?>"/></td>
        </tr>
          <td>&nbsp;</td>
          <td><input type="submit" name="cadastraCliente" id="cadastraCliente" value="Alterar" />  </td>
        </tr>
      </table>
         </form>
      <?php
        }
        if ($comum == 'relatorioLaboratorio'){
            $idEmpresa = $_SESSION['idEmpresa'];
            $numLaboratorios = mysql_num_rows(getLaboratorio($idEmpresa));
            $laboratorio = getLaboratorio($idEmpresa);
      ?>    
      <form action="xml/laboratorio" method="POST" target="_blank">
          <input type="hidden" name="idEmpresa" value="<?php echo $_SESSION["idEmpresa"]; ?>" />
          <input  type="submit" value="Baixar"/>
      </form>
      
      <p>&nbsp;</p>
      <table class="relatorio" width="950">
          <thead>
              <tr>
                  <th>Laboratório</th>
                  <th>Representante</th>
                  <th>Telefone</th>
              </tr>
          </thead>
          <tbody>
          <?php
          for ($i=0;$i<$numLaboratorios;$i++){
              mysql_data_seek($laboratorio, $i);
              $arrayLaboratorio = mysql_fetch_array($laboratorio);
                echo '<tr>';
            echo '<td>'.$arrayLaboratorio["nome"].'</td>';
            echo '<td>'.$arrayLaboratorio["representante"].'</td>';
            echo '<td>'.$arrayLaboratorio["telefone"].'</td>';
                echo '</tr>';
          }
          ?>
          </tbody>
      </table>
      <?php
        }
      ?>
</body>
</html>